home *** CD-ROM | disk | FTP | other *** search
/ Workbench Design / WB Collection.iso / workbench werkzeuge / scherz programme / amigaeyes / source / eyesdrawing.c < prev    next >
C/C++ Source or Header  |  1996-04-07  |  24KB  |  880 lines

  1. /*****************************************************************************/
  2. /*                       AmigaEyes V1.1a (02/12/1994)                        */
  3. /*                                                                           */
  4. /*       Author: Stéphane Poirier                                            */
  5. /*               Copyright © 1994 Stéphane Poirier. All right reserved       */
  6. /*                                                                           */
  7. /*****************************************************************************/
  8.  
  9. #include <libraries/commodities.h>
  10. #include <intuition/intuition.h>
  11. #include <intuition/classes.h>
  12. #include <intuition/classusr.h>
  13. #include <intuition/imageclass.h>
  14. #include <intuition/gadgetclass.h>
  15. #include <graphics/displayinfo.h>
  16. #include <graphics/clip.h>
  17. #include <graphics/view.h>
  18. #include <graphics/layers.h>
  19. #include <graphics/copper.h>
  20. #include <graphics/regions.h>
  21. #include <graphics/rastport.h>
  22. #include <graphics/gfxbase.h>
  23. #include <graphics/gfxmacros.h>
  24. #include <graphics/gels.h>
  25. #include <graphics/gfxbase.h>
  26. #include <clib/graphics_protos.h>
  27. #include <clib/exec_protos.h>
  28. #include <exec/memory.h>
  29. #include <stdlib.h>
  30. #include <stdio.h>
  31. #include <time.h>
  32.  
  33. #include <math.h>
  34. #include <mffp.h>
  35.  
  36. #include "eyes.h"
  37.  
  38. /*
  39. ** Dessin des yeux
  40. */
  41.  
  42. #ifdef ENTRELACE
  43.  int eyeX[37] = {-1,0,1,-2,-1,0,1,2,-3,-2,-1,0,1,2,3,-3,-2,-1,0,1,2,3,-3,-2,-1,0,1,2,3,-2,-1,0,1,2,-1,0,1};
  44.  int eyeY[37] = {-3,-3,-3,-2,-2,-2,-2,-2,-1,-1,-1,-1,-1,-1,-1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,2,2,2,2,2,3,3,3};
  45. #else
  46.  int eyeX[29] = {-1,0,1,-3,-2,-1,0,1,2,3,-4,-3,-2,-1,0,1,2,3,4,-3,-2,-1,0,1,2,3,-1,0,1};
  47.  int eyeY[29] = {-2,-2,-2,-1,-1,-1,-1,-1,-1,-1,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,2,2,2};
  48. #endif
  49.  
  50. float dcos[]= {  0.999999, 0.998027, 0.992115, 0.982287, 0.968583, 0.951057, 0.929777,
  51.                  0.904827, 0.876307, 0.844328, 0.809017, 0.770513, 0.728969, 0.684547,
  52.                  0.637424, 0.587785, 0.535827, 0.481754, 0.425779, 0.368125, 0.309017,
  53.                  0.248690, 0.187381, 0.125333, 0.062790, 0.000000 };
  54.  
  55. UBYTE *pixel;            /* Pointeur sur le tableau de flags de la fenetre */
  56.  
  57. UBYTE Bit[] = {0x80,       0x40,       0x20,       0x10,
  58.                 0x8,        0x4,        0x2,        0x1  };
  59.  
  60. struct Trace
  61. {
  62.   ULONG Adr[WNDY][8];        /* Adresse des lignes d'écran */
  63.   ULONG Adr1[WNDY];        /* Adresse des lignes d'écran */
  64.   ULONG Adr2[WNDY];        /* Adresse des lignes d'écran */
  65.   ULONG Adr3[WNDY];        /* Adresse des lignes d'écran */
  66.   ULONG Adr4[WNDY];        /* Adresse des lignes d'écran */
  67.   ULONG Adr5[WNDY];        /* Adresse des lignes d'écran */
  68.   ULONG Adr6[WNDY];        /* Adresse des lignes d'écran */
  69.   ULONG Adr7[WNDY];        /* Adresse des lignes d'écran */
  70.   ULONG Adr8[WNDY];        /* Adresse des lignes d'écran */
  71.   short Depth;            /* Profondeur de l'écran */
  72. } Trace;
  73.  
  74. struct BitMap *SBitmap;        /* La structure SuperBitMap pour la fenetre */
  75. extern BOOL Restart;
  76.  
  77. void WriteEye(struct Window *, int , int , int , int, int, int, BOOL);
  78. void ClearEye(struct Window *, int , int , int , int, int, int);
  79. BOOL TestWritePixel(int , int , int , int);
  80. BOOL TestClearPixel(int , int , int , int);
  81. BOOL FermePupilleGauche(struct Window *, int, int *);
  82. BOOL OuvrePupilleGauche(struct Window *, int, int *);
  83. BOOL FermePupilleDroite(struct Window *, int, int *);
  84. BOOL OuvrePupilleDroite(struct Window *, int, int *);
  85. void Plot(struct Window *, register SHORT, register SHORT, register int);
  86.  
  87. extern struct parametres Parametres;
  88. extern unsigned int clockInit[];
  89. extern USHORT refresh;
  90.  
  91. /*****************************************************************************/
  92.  
  93. int EyeCloseWindow(void)
  94. {
  95.     FreeMem(pixel, SIZEWNDX*SIZEWNDY);    /* Libere la memoire allouée */
  96.     return( FALSE);
  97. }
  98.  
  99. /*****************************************************************************/
  100.  
  101. void InitPlot(struct Window *EyeWnd, struct BitMap *SBitmap)
  102. {
  103.   PLANEPTR plan;        /* Pointeur sur un plan de bits */ 
  104.   ULONG addoffset, i;        
  105.   int y;
  106.   UWORD ligne;
  107.  
  108.   Trace.Depth = SBitmap->Depth;    /* Profondeur de l'écran */
  109.   ligne = WNDX >> 4;        /* Calcul de l'adresse du début de chaque ligne */
  110.   if (ligne & 1)
  111.     ligne ++;
  112.   ligne = ligne << 4;
  113.   
  114.   for(y = 0; y < WNDY; y++)
  115.   {
  116.     addoffset = (ligne * y) >> 3;   
  117.     for (i = 0; i < Trace.Depth; i++)
  118.     {
  119.       plan = SBitmap->Planes[i];    /* Adresses des plans ds la SuperBitmap */
  120.       Trace.Adr[y][i] = (ULONG)plan + addoffset;
  121.     }
  122.     Trace.Adr1[y] = Trace.Adr[y][0];
  123.     Trace.Adr2[y] = Trace.Adr[y][1];
  124.     Trace.Adr3[y] = Trace.Adr[y][2];
  125.     Trace.Adr4[y] = Trace.Adr[y][3];
  126.     Trace.Adr5[y] = Trace.Adr[y][4];
  127.     Trace.Adr6[y] = Trace.Adr[y][5];
  128.     Trace.Adr7[y] = Trace.Adr[y][6];
  129.     Trace.Adr8[y] = Trace.Adr[y][7];
  130.   }
  131. }
  132.     
  133. /*****************************************************************************/
  134.  
  135. void InitEyes(struct Window *EyeWnd, struct BitMap *SBitmap)
  136. {
  137.   unsigned int clock[2];    /* Horloge */
  138.   int x;
  139.  
  140.   SetRast(EyeWnd->RPort,Parametres.fenetre);        /* Vide la SuperBitMap */
  141.   SetAPen(EyeWnd->RPort,Parametres.bord);        /* Couleur du crayon */
  142.  
  143. #ifdef ENTRELACE
  144.   DrawEllipse(EyeWnd->RPort,rEYE,yEYE,15,15);
  145.   DrawEllipse(EyeWnd->RPort,rEYE,yEYE,14,14);
  146.   DrawEllipse(EyeWnd->RPort,lEYE,yEYE,15,15);
  147.   DrawEllipse(EyeWnd->RPort,lEYE,yEYE,14,14);
  148.   DrawEllipse(EyeWnd->RPort,lEYE,yEYE,14,15);
  149.   DrawEllipse(EyeWnd->RPort,rEYE,yEYE,14,15);
  150.   DrawEllipse(EyeWnd->RPort,lEYE,yEYE,15,14);
  151.   DrawEllipse(EyeWnd->RPort,rEYE,yEYE,15,14);
  152.   DrawEllipse(EyeWnd->RPort,lEYE,yEYE,16,14);
  153.   DrawEllipse(EyeWnd->RPort,rEYE,yEYE,16,14);
  154.   DrawEllipse(EyeWnd->RPort,lEYE,yEYE,16,15);
  155.   DrawEllipse(EyeWnd->RPort,rEYE,yEYE,16,15);
  156.   DrawEllipse(EyeWnd->RPort,lEYE,yEYE,13,15);
  157.   DrawEllipse(EyeWnd->RPort,rEYE,yEYE,13,15);
  158.   DrawEllipse(EyeWnd->RPort,lEYE,yEYE,13,13);
  159.   DrawEllipse(EyeWnd->RPort,rEYE,yEYE,13,13);
  160.   DrawEllipse(EyeWnd->RPort,lEYE,yEYE,13,14);
  161.   DrawEllipse(EyeWnd->RPort,rEYE,yEYE,13,14);
  162. #else
  163.   DrawEllipse(EyeWnd->RPort,lEYE,yEYE,17,8);    /* Dessine le contour des yeux */
  164.   DrawEllipse(EyeWnd->RPort,rEYE,yEYE,17,8);
  165.   DrawEllipse(EyeWnd->RPort,lEYE,yEYE,15,7);
  166.   DrawEllipse(EyeWnd->RPort,rEYE,yEYE,15,7);
  167.   DrawEllipse(EyeWnd->RPort,lEYE,yEYE,16,7);
  168.   DrawEllipse(EyeWnd->RPort,rEYE,yEYE,16,7);
  169.   DrawEllipse(EyeWnd->RPort,lEYE,yEYE,14,8);
  170.   DrawEllipse(EyeWnd->RPort,rEYE,yEYE,14,8);
  171.   DrawEllipse(EyeWnd->RPort,lEYE,yEYE,15,8);
  172.   DrawEllipse(EyeWnd->RPort,rEYE,yEYE,15,8);
  173.   DrawEllipse(EyeWnd->RPort,lEYE,yEYE,16,8);
  174.   DrawEllipse(EyeWnd->RPort,rEYE,yEYE,16,8);
  175.   DrawEllipse(EyeWnd->RPort,lEYE,yEYE,18,8);
  176.   DrawEllipse(EyeWnd->RPort,rEYE,yEYE,18,8);
  177. #endif
  178.  
  179.   x = timer(clock);        /* Prépare la génération de nombres aléatoires */
  180.   srand(clock[1]);
  181.   
  182. /* Allocation d'un tableau de flags représentant l'état de la SuperBitMap */
  183.  
  184.   if((pixel = (UBYTE *)AllocMem(SIZEWNDX*SIZEWNDY,MEMF_PUBLIC|MEMF_CLEAR)) == NULL)
  185.     printf("erreur d'allocation mémoire\n");
  186.  
  187.   if (Parametres.drawing == CUSTOM_DRAW)
  188.   {
  189.     LockLayerRom(EyeWnd->WLayer);
  190.     SyncSBitMap(EyeWnd->WLayer);
  191.     UnlockLayerRom(EyeWnd->WLayer);
  192.   }
  193. }
  194.  
  195. /*****************************************************************************/
  196. /*             Routine de gestion des yeux                 */
  197. /*****************************************************************************/
  198.  
  199. BOOL DrawingEyes(struct Window *EyeWnd, struct BitMap *SBitmap, int offy)
  200. {
  201.   BOOL reveil = FALSE;        /* Valeur de retour: y-a-t-il eu arret de la souris */
  202.                 /* puis mvt ? */
  203.  
  204.   static int xr, yr, xl, yl, mx, my;
  205.   static int compteur_clin_d_oeil_gauche = 0;    /* Compteurs pour clins d'oeil */
  206.   static int compteur_clin_d_oeil_droit = 0;
  207.   static unsigned int wait_cligne_gauche = 02;    /* Delais pour clins d'oeil */
  208.   static unsigned int wait_cligne_droit  = 02;
  209.   float dr, dl, dxl, dxr, dy, x,y;
  210.   int tx, TempsEcoule;
  211.   unsigned int clockVal[2];
  212.   unsigned int xx, yy,i;
  213.   static BOOL debut = TRUE;        /* Premier passage dans la routine */
  214.   static BOOL ferme_pupilles = FALSE;    /* Pupilles fermantes = VRAI sinon FAUX */
  215.   static BOOL ouvre_pupilles = FALSE;    /* Pupilles ouvrante ... */
  216.   static BOOL cligne_gauche = FALSE;    /* Clin d'oeil gauche en cours */
  217.   static BOOL decligne_gauche = FALSE;    /* "Dé"clin d'oeil gauche en cours */
  218.   static BOOL cligne_droit = FALSE;    /* Idem oeil droit */
  219.   static BOOL decligne_droit = FALSE;
  220.   static BOOL pupille_fermee = FALSE;    /* Pupilles fermées */
  221.   static int rRayon = +(REYE-2);      /* Rayon des ellipse pour tracer paupieres */
  222.   static int lRayon = +(REYE-2);
  223.  
  224.   if (Restart)
  225.   {
  226.     ferme_pupilles = FALSE;
  227.     ouvre_pupilles = FALSE;
  228.     cligne_gauche = TRUE;
  229.     decligne_gauche = FALSE;
  230.     cligne_droit = TRUE;
  231.     decligne_droit = FALSE;
  232.     pupille_fermee = FALSE;
  233.   }    
  234. /* Est-ce qu'on est pas en train d'ouvrir ou fermer une pupille, ou est-ce
  235. ** les pupilles ne sont pas deja fermees ? 
  236. */
  237.    tx = timer(clockVal);
  238.    TempsEcoule = clockVal[0] - clockInit[0];
  239.  
  240.   if ((!pupille_fermee) && (!ouvre_pupilles) && (!ferme_pupilles))
  241.   {
  242.     if (TempsEcoule > Parametres.timeout) /* Si la souris n'a pas bougé */
  243.       ferme_pupilles = TRUE;  /* durant le temps definit alors on ferme les pupilles */
  244.       
  245.     compteur_clin_d_oeil_gauche++; /* Incrémenter le compteur pour clin d'oeil */
  246.  
  247. /* Est-on prêt à cligner de l'oeil ? et n'est-on pas en train de fermer les
  248. ** pupilles ?
  249. */
  250.     if ((compteur_clin_d_oeil_gauche >= wait_cligne_gauche) && (!ferme_pupilles))
  251.       cligne_gauche = TRUE;
  252.       
  253.     if(decligne_gauche)        /* releve la paupiere */
  254.     {
  255.       for(i = 0; i<REYE*2; i++)
  256.       { 
  257.         decligne_gauche = (!OuvrePupilleGauche(EyeWnd, Parametres.fond, &lRayon));
  258.         WriteEye(EyeWnd, xl, yl, xl, yl, Parametres.pupille, 
  259.                  Parametres.paupiere, decligne_gauche);    /* retrace pupille */
  260.  
  261.         if (Parametres.drawing == CUSTOM_DRAW)
  262.         {
  263.           LockLayerRom(EyeWnd->WLayer);        /* Recopie dans la bitmap de */
  264.           CopySBitMap(EyeWnd->WLayer);        /* l'ecran la derniere opération */
  265.           UnlockLayerRom(EyeWnd->WLayer);    /* graphique */
  266.         }
  267.  
  268.         if (!decligne_gauche) break;
  269.       }
  270.     decligne_gauche = FALSE;
  271.     wait_cligne_gauche = (((unsigned int)rand() >> 23) + (1 << 8)) 
  272.                          / refresh;
  273.     }
  274.  
  275.     if(cligne_gauche)
  276.     {
  277.       for(i = 0; i<2*REYE; i++)
  278.       { 
  279.         cligne_gauche = (!FermePupilleGauche(EyeWnd, Parametres.paupiere, &lRayon));
  280.  
  281.         if (Parametres.drawing == CUSTOM_DRAW)
  282.         {
  283.           LockLayerRom(EyeWnd->WLayer);        /* Recopie dans la bitmap de */
  284.           CopySBitMap(EyeWnd->WLayer);        /* l'ecran la derniere opération */
  285.           UnlockLayerRom(EyeWnd->WLayer);    /* graphique */
  286.         }
  287.  
  288.         if (!cligne_gauche) break;
  289.       }
  290.     decligne_gauche = TRUE;
  291.     cligne_gauche = FALSE;
  292.     compteur_clin_d_oeil_gauche = 0;
  293.     }
  294.     
  295.     compteur_clin_d_oeil_droit++;
  296.     if ((compteur_clin_d_oeil_droit >= wait_cligne_droit) && (!ferme_pupilles))
  297.       cligne_droit = TRUE;
  298.       
  299.     if(decligne_droit)
  300.     {
  301.       for(i = 0; i<REYE*2; i++)
  302.       { 
  303.         decligne_droit = (!OuvrePupilleDroite(EyeWnd, Parametres.fond, &rRayon));
  304.         WriteEye(EyeWnd, xr, yr, xr, yr, Parametres.pupille,
  305.                  Parametres.paupiere, decligne_droit);
  306.  
  307.         if (Parametres.drawing == CUSTOM_DRAW)
  308.         {
  309.           LockLayerRom(EyeWnd->WLayer);        /* Recopie dans la bitmap de */
  310.           CopySBitMap(EyeWnd->WLayer);        /* l'ecran la derniere opération */
  311.           UnlockLayerRom(EyeWnd->WLayer);    /* graphique */
  312.         }
  313.  
  314.         if (!decligne_droit) break;
  315.       }
  316.     decligne_droit = FALSE;
  317.     wait_cligne_droit = (((unsigned int)rand() >> 23) + (1 << 8))
  318.                         / refresh;
  319.     }
  320.  
  321.     if(cligne_droit)
  322.     {
  323.       for(i = 0; i<2*REYE; i++)
  324.       { 
  325.         cligne_droit = (!FermePupilleDroite(EyeWnd, Parametres.paupiere, &rRayon));
  326.  
  327.         if (Parametres.drawing == CUSTOM_DRAW)
  328.         {
  329.           LockLayerRom(EyeWnd->WLayer);        /* Recopie dans la bitmap de */
  330.           CopySBitMap(EyeWnd->WLayer);        /* l'ecran la derniere opération */
  331.           UnlockLayerRom(EyeWnd->WLayer);    /* graphique */
  332.         }
  333.  
  334.         if (!cligne_droit) break;
  335.       }
  336.     decligne_droit = TRUE;
  337.     cligne_droit = FALSE;
  338.     compteur_clin_d_oeil_droit = 0;
  339.     }
  340.   }
  341.   
  342.   if (ferme_pupilles)
  343.   {
  344.     ferme_pupilles = (!FermePupilleGauche(EyeWnd, Parametres.paupiere, &lRayon));
  345.     ferme_pupilles = (!FermePupilleDroite(EyeWnd, Parametres.paupiere, &rRayon));
  346.  
  347.     if (Parametres.drawing == CUSTOM_DRAW)
  348.     {
  349.       LockLayerRom(EyeWnd->WLayer);        /* Recopie dans la bitmap de */
  350.       CopySBitMap(EyeWnd->WLayer);        /* l'ecran la derniere opération */
  351.       UnlockLayerRom(EyeWnd->WLayer);        /* graphique */
  352.     }
  353.  
  354.     pupille_fermee = !ferme_pupilles;
  355.   }
  356.  
  357.   if (ouvre_pupilles)
  358.   {
  359.     ouvre_pupilles = (!OuvrePupilleGauche(EyeWnd, Parametres.fond, &lRayon));
  360.     ouvre_pupilles = (!OuvrePupilleDroite(EyeWnd, Parametres.fond, &rRayon));
  361.  
  362.     if (Parametres.drawing == CUSTOM_DRAW)
  363.     {
  364.       LockLayerRom(EyeWnd->WLayer);        /* Recopie dans la bitmap de */
  365.       CopySBitMap(EyeWnd->WLayer);        /* l'ecran la derniere opération */
  366.       UnlockLayerRom(EyeWnd->WLayer);    /* graphique */
  367.     }
  368.  
  369.     WriteEye(EyeWnd, xl, yl, xl, yl, Parametres.pupille,
  370.              Parametres.paupiere, ouvre_pupilles);
  371.     WriteEye(EyeWnd, xr, yr, xr, yr, Parametres.pupille,
  372.              Parametres.paupiere, ouvre_pupilles);
  373.   }
  374.     
  375.   if  ((EyeWnd->MouseX != mx + OFFX) || (EyeWnd->MouseY != my + offy))
  376.   {
  377.     if (TempsEcoule > 1)    /* On renvoie "reveil" si 1 sec au moins */
  378.       reveil = TRUE;            /* s'est ecoulée depuis le dernier mvt. */
  379.  
  380.     clockInit[1] = clockVal[1];
  381.     clockInit[0] = clockVal[0];
  382.     
  383.     refresh = Parametres.refresh;
  384.     
  385.     if((ferme_pupilles) || (pupille_fermee))
  386.     {
  387.       ouvre_pupilles = TRUE;
  388.       ferme_pupilles = FALSE;
  389.       pupille_fermee = FALSE;
  390.     }
  391.     
  392.     mx = EyeWnd->MouseX - OFFX;
  393.     my = EyeWnd->MouseY - offy;
  394.     
  395.     dxl = (float)mx - (float)lEYE;    /* Distance de la pupille au pointeur */
  396.     dxr = (float)mx - (float)rEYE;
  397. #ifdef ENTRELACE
  398.     dy  = (float)my - (float)yEYE;
  399. #else
  400.     dy  = ((float)my - (float)yEYE) * 2;
  401. #endif
  402.     dl = sqrt(SQR(dxl) + SQR(dy));
  403.     dr = sqrt(SQR(dxr) + SQR(dy));
  404.  
  405.     if (dl > RLIM)            /* Si distance > rayon de l'oeil */
  406.     {
  407.       x = (float)RLIM/dl * dxl + (float)lEYE;
  408. #ifdef ENTRELACE
  409.       y = (float)RLIM/dl * dy  + (float)yEYE;
  410. #else
  411.       y = ((float)REYE/dl * dy)/2 + (float)yEYE;
  412. #endif
  413.       xx = (int)(x+0.5);
  414.       yy = (int)(y+0.5);
  415.     }
  416.     else                /* Sinon Pupille sous le pointeur */
  417.     {
  418.       xx = mx;
  419.       yy = my;
  420.     }  
  421.     if ((xl != xx) || (yl != yy))    /* Si la pupille est déplacée */
  422.     {                    /* Alors on la redessine */
  423.       WriteEye(EyeWnd, xx, yy, xl, yl, Parametres.pupille,
  424.                Parametres.paupiere, ouvre_pupilles);
  425.      if (debut == FALSE)
  426.         ClearEye(EyeWnd, xx, yy, xl, yl, Parametres.fond, Parametres.paupiere);
  427.       xl = xx; yl = yy;
  428.     }
  429.  
  430.     if (dr > RLIM)            /* Idem pupille droite */
  431.     {
  432.       x = (float)RLIM/dr * dxr + (float)rEYE;
  433. #ifdef ENTRELACE
  434.       y = (float)RLIM/dr * dy  + (float)yEYE;
  435. #else
  436.       y = ((float)REYE/dr * dy)/2 + (float)yEYE;
  437. #endif
  438.       xx = (int)(x+0.5);
  439.       yy = (int)(y+0.5);
  440.     }
  441.     else
  442.     {
  443.       xx = mx;
  444.       yy = my;
  445.     }
  446.     if ((xr != xx) || (yr != yy))
  447.     {
  448.       WriteEye(EyeWnd, xx, yy, xr, yr, Parametres.pupille,
  449.                Parametres.paupiere, ouvre_pupilles);
  450.       if (debut == FALSE)
  451.         ClearEye(EyeWnd, xx, yy, xr, yr, Parametres.fond, Parametres.paupiere);
  452.       xr = xx; yr = yy;
  453.     }
  454.  
  455.     if (Parametres.drawing == CUSTOM_DRAW)
  456.     {
  457.       LockLayerRom(EyeWnd->WLayer);        /* Recopie dans la bitmap de */
  458.       CopySBitMap(EyeWnd->WLayer);         /* l'ecran la derniere opération */
  459.       UnlockLayerRom(EyeWnd->WLayer);        /* graphique */
  460.     }
  461.   }
  462.   else
  463.   {
  464.     if (TempsEcoule >= 1)               /* Si la souris n'a pas bougé */
  465.     {
  466.       refresh = SLEEP;            /* pendant au moins 1 sec. */
  467.     }
  468.     
  469.   }
  470.   debut = FALSE;
  471.   return (reveil);
  472. }
  473.  
  474. /*****************************************************************************/
  475. /*               Dessine une pupille                     */
  476. /*****************************************************************************/
  477.  
  478. void WriteEye(struct Window *EyeWnd, int x, int y, 
  479.               int xold, int yold, int c1, int c2, BOOL ouvre_pupille)
  480. {
  481.   register int i, x1, y1;
  482.   UBYTE *c;
  483.   
  484.   SetAPen(EyeWnd->RPort,c1);
  485.   
  486. #ifdef ENTRELACE
  487.   for (i=0; i < 37; i++)    /* Chaque pupille comporte 37 pixels en version LACE */
  488. #else
  489.   for (i=0; i < 29; i++)        /* Chaque pupille comporte 29 pixels */
  490. #endif
  491.   {
  492.     x1 = x+eyeX[i];
  493.     y1 = y+eyeY[i];
  494.     c = pixel+SIZEWNDX*x1+y1;
  495.     
  496.       if ((*c != c2) && (*c != c1))    /* Si le point n'est pas deja affiché */
  497.       {
  498.         Plot(EyeWnd, x1, y1, c1);
  499.         *c = c1;
  500.       }
  501.  
  502.   }
  503. }
  504.  
  505. /*****************************************************************************/
  506. /*                Efface une pupille                     */
  507. /*****************************************************************************/
  508.  
  509. void ClearEye(struct Window *EyeWnd, int x, int y, int xold, int yold, int c1, int c2)
  510. {
  511.   register int i, x1, y1;
  512.   UBYTE *c;
  513.   
  514.   SetAPen(EyeWnd->RPort,c1);
  515.   
  516. #ifdef ENTRELACE
  517.   for (i = 0; i < 37; i++)    /* Chaque pupille comporte 37 pixels en version LACE */
  518. #else
  519.   for (i = 0; i < 29; i++)        /* Chaque pupille comporte 29 pixels */
  520. #endif
  521.   {
  522.     x1 = xold+eyeX[i];
  523.     y1 = yold+eyeY[i];
  524.     c = pixel+SIZEWNDX*x1+y1;
  525.  
  526.     if (!TestClearPixel(x1, y1, x, y))
  527.       if (*c != c2)
  528.       {
  529.         Plot(EyeWnd, x1, y1, c1);
  530.         *c = c1;
  531.       }
  532.  
  533.   }
  534. }
  535.  
  536. /*****************************************************************************/
  537. /*        Test pour déterminer si on peut effacer un pixel         */
  538. /*****************************************************************************/
  539.  
  540. BOOL TestClearPixel(int x, int y, int xnew, int ynew)
  541. {
  542.   register int i;
  543.   BOOL ret = FALSE;
  544.   
  545. #ifdef ENTRELACE
  546.   for (i = 0; i < 37; i++)    /* Chaque pupille comporte 37 pixels en version LACE */
  547. #else
  548.   for (i = 0; i < 29; i++)        /* Chaque pupille comporte 29 pixels */
  549. #endif
  550.   {
  551.     if ((x == xnew + eyeX[i]) && (y == ynew + eyeY[i]))
  552.     {
  553.       ret = TRUE;
  554.       break;
  555.     }
  556.   }
  557.   return(ret);
  558. }
  559.  
  560. /*****************************************************************************/
  561.  
  562. BOOL FermePupilleGauche(struct Window *EyeWnd, int c, int * PRayon)
  563. {
  564.   SHORT i, xp, yp;
  565. #ifdef ENTRELACE
  566.   static float rx = REYE-0.5;
  567. #else
  568.   static float rx = 2*REYE+0.5;
  569. #endif
  570.   float ry, x, y;
  571.   
  572.   float sgn = 1;
  573.   
  574.   if (*PRayon < 0)
  575.   {
  576.     sgn = -1;
  577.     ry = -(*PRayon);
  578.   }
  579.   else
  580.   {
  581.     ry = *PRayon;
  582.   }
  583.  
  584.   SetAPen(EyeWnd->RPort, c);
  585.   
  586.   for (i = 0; i <= RESOL; i++)
  587.   {
  588.     x = (float)rx * sgn*dcos[i];
  589.     y = -(float)ry * sgn*dcos[RESOL-i];
  590.     
  591.     xp = (int)(x+0.5+lEYE);
  592.     yp = (int)(y+0.5+yEYE);    
  593.     Plot(EyeWnd, xp, yp, c);
  594.     *(pixel+SIZEWNDX*xp+yp) = c;
  595.     
  596.     xp = (int)(-x+0.5+lEYE);
  597.     Plot(EyeWnd, xp, yp, c);
  598.     *(pixel+SIZEWNDX*xp+yp) = c;
  599.   }
  600.  
  601.   (*PRayon)--;
  602. #ifdef ENTRELACE
  603.   if (*PRayon < -(REYE-2))
  604. #else
  605.   if (*PRayon < -(REYE-1))
  606. #endif
  607.   {
  608.     (*PRayon)++;
  609.     return(TRUE);
  610.   }
  611.   else
  612.     return(FALSE);
  613. }
  614.  
  615. /*****************************************************************************/
  616.  
  617. BOOL OuvrePupilleGauche(struct Window *EyeWnd, int c, int *PRayon)
  618. {
  619.   SHORT i, xp, yp;
  620. #ifdef ENTRELACE
  621.   static float rx = REYE-0.5;
  622. #else
  623.   static float rx = REYE*2+0.5;
  624. #endif
  625.   float ry, x, y;
  626.   
  627.   float sgn = 1;
  628.   
  629.   if (*PRayon < 0)
  630.   {
  631.     sgn = -1;
  632.     ry = -*PRayon;
  633.   }
  634.   else
  635.   {
  636.     ry = *PRayon;
  637.   }
  638.  
  639.   SetAPen(EyeWnd->RPort, c);
  640.   
  641.   for (i = 0; i <= RESOL; i++)
  642.   {
  643.     x = (float)rx * sgn*dcos[i];
  644.     y = -(float)ry * sgn*dcos[RESOL-i];
  645.     
  646.     xp = (int)(x+lEYE+0.5);
  647.     yp = (int)(y+yEYE+0.5);    
  648.     Plot(EyeWnd, xp, yp, c);
  649.     *(pixel+SIZEWNDX*xp+yp) = c;
  650.     
  651.     xp = (int)(-x+lEYE+0.5);
  652.     Plot(EyeWnd, xp, yp, c);
  653.     *(pixel+SIZEWNDX*xp+yp) = c;
  654.   }
  655.  
  656.   (*PRayon)++;
  657. #ifdef ENTRELACE
  658.   if (*PRayon > (REYE-2))
  659. #else
  660.   if (*PRayon > (REYE-1))
  661. #endif
  662.   {
  663.     (*PRayon)--;
  664.     return(TRUE);
  665.   }
  666.   else
  667.    return(FALSE);
  668. }
  669.  
  670. /*****************************************************************************/
  671.  
  672. BOOL FermePupilleDroite(struct Window *EyeWnd, int c, int * PRayon)
  673. {
  674.   SHORT i, xp, yp;
  675. #ifdef ENTRELACE
  676.   static float rx = REYE-0.5;
  677. #else
  678.   static float rx = REYE*2+0.5;
  679. #endif
  680.   float ry, x, y;
  681.   
  682.   float offsetangle = 0;
  683.   float sgn = 1;
  684.   
  685.   if (*PRayon < 0)
  686.   {
  687.     offsetangle = PI;
  688.     sgn = -1;
  689.     ry = -(*PRayon);
  690.   }
  691.   else
  692.   {
  693.     ry = *PRayon;
  694.   }
  695.  
  696.   SetAPen(EyeWnd->RPort, c);
  697.   
  698.   for (i = 0; i <= RESOL; i++)
  699.   {
  700.     x = (float)rx * sgn*dcos[i];
  701.     y = -(float)ry * sgn*dcos[RESOL-i];
  702.     
  703.     xp = (int)(x+rEYE+0.5);
  704.     yp = (int)(y+yEYE+0.5);    
  705.     Plot(EyeWnd, xp, yp, c);
  706.     *(pixel+SIZEWNDX*xp+yp) = c;
  707.     
  708.     xp = (int)(-x+rEYE+0.5);
  709.     Plot(EyeWnd, xp, yp, c);
  710.     *(pixel+SIZEWNDX*xp+yp) = c;
  711.   }
  712.  
  713.   (*PRayon)--;
  714.  
  715. #ifdef ENTRELACE
  716.   if (*PRayon < -(REYE-2))
  717. #else
  718.   if (*PRayon < -(REYE-1))
  719. #endif
  720.   {
  721.     (*PRayon)++;
  722.     return(TRUE);
  723.   }
  724.   else
  725.     return(FALSE);
  726. }
  727.  
  728. /*****************************************************************************/
  729.  
  730. BOOL OuvrePupilleDroite(struct Window *EyeWnd, int c, int *PRayon)
  731. {
  732.   SHORT i, xp, yp;
  733. #ifdef ENTRELACE
  734.   static float rx = REYE-0.5;
  735. #else
  736.   static float rx = REYE*2+0.5;
  737. #endif
  738.   float ry, x, y;
  739.   
  740.   float offsetangle = 0;
  741.   float sgn = 1;
  742.   
  743.   if (*PRayon < 0)
  744.   {
  745.     offsetangle = PI;
  746.     sgn = -1;
  747.     ry = -*PRayon;
  748.   }
  749.   else
  750.   {
  751.     ry = *PRayon;
  752.   }
  753.  
  754.   SetAPen(EyeWnd->RPort, c);
  755.   
  756.   for (i = 0; i <= RESOL; i++)
  757.   {
  758.     x = (float)rx * sgn*dcos[i];
  759.     y = -(float)ry * sgn*dcos[RESOL-i];
  760.     
  761.     xp = (int)(x+rEYE+0.5);
  762.     yp = (int)(y+yEYE+0.5);    
  763.     Plot(EyeWnd, xp, yp, c);
  764.     *(pixel+SIZEWNDX*xp+yp) = c;
  765.     
  766.     xp = (int)(-x+rEYE+0.5);
  767.     Plot(EyeWnd, xp, yp, c);
  768.     *(pixel+SIZEWNDX*xp+yp) = c;
  769.   }
  770.  
  771.   (*PRayon)++;
  772.  
  773. #ifdef ENTRELACE
  774.   if (*PRayon > (REYE-2))
  775. #else
  776.   if (*PRayon > (REYE-1))
  777. #endif
  778.   {
  779.     (*PRayon)--;
  780.     return(TRUE);
  781.   }
  782.   else
  783.    return(FALSE);
  784. }
  785.  
  786. /*****************************************************************************/
  787. /*            Routine d'affichage d'un point                 */
  788. /*****************************************************************************/
  789.  
  790. void Plot(struct Window *EyeWnd, register SHORT x, register SHORT y, register int c)
  791. {
  792.   register UBYTE *adresse;
  793.   register etbit, oubit;
  794.   register ULONG addoffset;
  795.       
  796.   if (Parametres.drawing == CUSTOM_DRAW)
  797.   {
  798.     if ((x <= EyeWnd->Width) && (y <= EyeWnd->Height))
  799.     {
  800.       addoffset = x >> 3;
  801.  
  802.       oubit = Bit[x & 7];
  803.       etbit = 255 - oubit;
  804.       
  805.       adresse = (UBYTE *)(Trace.Adr1[y] + addoffset);
  806.       if (c & 1)
  807.         *(adresse) |= oubit;
  808.       else
  809.         *(adresse) &= etbit;
  810.  
  811.       if (Trace.Depth > 1)
  812.       {
  813.         adresse = (UBYTE *)(Trace.Adr2[y] + addoffset);
  814.         if (c & 2)
  815.           *(adresse) |= oubit;
  816.         else
  817.           *(adresse) &= etbit;
  818.  
  819.         if (Trace.Depth > 2)
  820.         {
  821.           adresse = (UBYTE *)(Trace.Adr3[y] + addoffset);
  822.           if (c & 4)
  823.             *(adresse) |= oubit;
  824.           else
  825.             *(adresse) &= etbit;
  826.  
  827.           if (Trace.Depth > 3)
  828.           {
  829.             adresse = (UBYTE *)(Trace.Adr4[y] + addoffset);
  830.             if (c & 8)
  831.               *(adresse) |= oubit;
  832.             else
  833.               *(adresse) &= etbit;
  834.  
  835.             if (Trace.Depth > 4)
  836.             {
  837.               adresse = (UBYTE *)(Trace.Adr5[y] + addoffset);
  838.               if (c & 16)
  839.                 *(adresse) |= oubit;
  840.               else
  841.                 *(adresse) &= etbit;
  842.  
  843.               if (Trace.Depth > 5)
  844.               {
  845.                 adresse = (UBYTE *)(Trace.Adr6[y] + addoffset);
  846.                 if (c & 32)
  847.                   *(adresse) |= oubit;
  848.                 else
  849.                   *(adresse) &= etbit;
  850.  
  851.                 if (Trace.Depth > 6)
  852.                 {
  853.                   adresse = (UBYTE *)(Trace.Adr7[y] + addoffset);
  854.                   if (c & 64)
  855.                     *(adresse) |= oubit;
  856.                   else
  857.                     *(adresse) &= etbit;
  858.  
  859.                   if (Trace.Depth > 7)
  860.                   {
  861.                     adresse = (UBYTE *)(Trace.Adr8[y] + addoffset);
  862.                     if (c & 128)
  863.                       *(adresse) |= oubit;
  864.                     else
  865.                       *(adresse) &= etbit;
  866.                   }
  867.                 }
  868.               }
  869.             }
  870.           }
  871.         }
  872.       }
  873.     }
  874.   }
  875.   else
  876.   {
  877.     WritePixel(EyeWnd->RPort, x, y);
  878.   }
  879. }
  880.